<template>
  <div>
    <el-card>
      <el-row :gutter="20">
        <el-col :span="6">
          所属类型:
          <el-select v-model="typeId" placeholder="请选择" style="width: 73%" size="mini" @change="loadData()">
            <el-option v-for="item in menulist" :key="item.id" :label="item.authName" :value="item.id"> </el-option>
          </el-select>
        </el-col>
        <el-col :span="4">
          编号:
          <el-input style="width: 100px" size="mini" v-model="queryInfo.number"></el-input>
        </el-col>
        <el-col :span="4">
          牌号:
          <el-input style="width: 100px" size="mini" v-model="queryInfo.mark"></el-input>
        </el-col>
        <el-col :span="4">
          <el-button type="primary" size="mini" @click="queryData">查询</el-button>
        </el-col>
      </el-row>
      <el-row style="margin: 10px 0 10px">
        <el-col :span="2">
          <el-button type="primary" size="mini" @click="addParameterVisible = true"><i class="el-icon-plus"></i>添加</el-button>
        </el-col>
        <el-col :span="2" style="margin-left: 10px">
          <el-button type="primary" size="mini" @click="showImport"><i class="el-icon-arrow-right"></i>导入</el-button>
        </el-col>
      </el-row>

      <!-- 合并 -->
      <el-table :data="parameterList" border height="300px" style="margin: 10px 0 10px">
        <el-table-column align="center" type="index"></el-table-column>
        <el-table-column align="center" v-if="tableHeader[0]" prop="specification" label="样品规格"></el-table-column>
        <el-table-column align="center" v-if="tableHeader[1]" prop="grade" label="牌号"></el-table-column>
        <el-table-column align="center" v-if="tableHeader[2]" prop="innerDiameter" label="内径(m)"></el-table-column>
        <el-table-column align="center" v-if="tableHeader[3]" prop="outerDiameter" label="外径(m)"></el-table-column>
        <el-table-column align="center" v-if="tableHeader[4]" prop="height" width="110" label="磁环高度(m)"></el-table-column>
        <el-table-column align="center" v-if="tableHeader[5]" prop="mass" label="质量(kg)"></el-table-column>
        <el-table-column align="center" v-if="tableHeader[6]" prop="ringWidth" label="环宽(m)"></el-table-column>
        <el-table-column align="center" v-if="tableHeader[7]" prop="volume" width="110" label="体积(m^3)"></el-table-column>
        <el-table-column align="center" v-if="tableHeader[8]" prop="thinkness" width="110" label="单片厚度(m)"></el-table-column>
        <el-table-column align="center" v-if="tableHeader[9]" prop="length" width="110" label="单片长度(m)"></el-table-column>
        <el-table-column align="center" v-if="tableHeader[10]" prop="width" width="110" label="单片宽度(m)"></el-table-column>
        <el-table-column align="center" v-if="tableHeader[11]" prop="heightEff" width="130" label="磁环有效高度(m)"></el-table-column>
        <el-table-column align="center" v-if="tableHeader[12]" prop="massEff" width="110" label="有效质量(kg)"></el-table-column>
        <el-table-column align="center" v-if="tableHeader[13]" prop="ringWidthEff" width="110" label="有效环宽(m)"></el-table-column>
        <el-table-column align="center" v-if="tableHeader[14]" prop="ringWidthEff" width="120" label="有效体积(m^3)"></el-table-column>
        <el-table-column align="center" v-if="tableHeader[15]" prop="thicknessEff" width="110" label="有效厚度(m)"></el-table-column>
        <el-table-column align="center" v-if="tableHeader[16]" prop="magneticLengthEff" width="130" label="有效磁路长度(m)"></el-table-column>
        <el-table-column align="center" v-if="tableHeader[17]" prop="slotBottomDiameter" width="130" label="槽底圆直径(m)"></el-table-column>
        <el-table-column align="center" v-if="tableHeader[18]" prop="area" width="170" label="磁环轴向截面积(m^2)"></el-table-column>
        <el-table-column align="center" v-if="tableHeader[19]" prop="massDensity" width="170" label="实际质量密度(kg/m^3)"></el-table-column>
        <el-table-column align="center" v-if="tableHeader[20]" prop="ratedMassDensity" width="170" label="标称质量密度(kg/m^3)"></el-table-column>
        <el-table-column align="center" v-if="tableHeader[21]" prop="numOfSheets" label="片数"></el-table-column>
        <el-table-column align="center" v-if="tableHeader[22]" prop="primaryTurns" width="110" label="初级绕组匝数"></el-table-column>
        <el-table-column align="center" v-if="tableHeader[23]" prop="secondaryTurns" width="110" label="次级绕组匝数"></el-table-column>
        <el-table-column align="center" v-if="tableHeader[24]" prop="magneticArea" width="140" label="磁路截面积(m^2)"></el-table-column>
        <el-table-column align="center" v-if="tableHeader[25]" prop="stackingFactor" label="叠压系数"></el-table-column>
        <el-table-column align="center" v-if="tableHeader[26]" prop="magneticLength" width="130" label="表观磁路长度(m)"></el-table-column>
        <el-table-column align="center" v-if="tableHeader[27]" label="备注" prop="remarks"></el-table-column>
        <el-table-column align="center" label="操作"> </el-table-column>
      </el-table>

      <!-- 分页区 -->
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="queryInfo.pagenum" :page-sizes="[100, 200, 400, 800]" :page-size="queryInfo.pagesize" layout="total, sizes, prev, pager, next, jumper" :total="total"> </el-pagination>
    </el-card>
    <!-- 导入按钮 -->
    <el-dialog title="提示" :visible.sync="importTag" width="60%">
      <div style="font-size: 20px; margin-left: 40px">请下载导入模板进行导入</div>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" style="margin-right: 20px" @click="exportData">下载模板</el-button>
        <a-upload name="file" :action="uploadUrl" accept=".xls,.xlsx" :data="paramData" :multiple="true" @change="handleChange" :showUploadList="false">
          <el-button type="primary">已有模板，立即导入</el-button>
        </a-upload>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      paramData: {
        name: '2'
      },
      uploadUrl: 'http://59.172.104.174:30669/admin/uploadLessonFile',
      importTag: false,
      tableHeader: [],
      //样品规格,牌号,内径,外径,磁环高度,质量,环宽,体积,单片厚度,单片长度,单片宽度,磁环有效高度,有效质量,有效环宽,有效体积,有效厚度,有效磁路长度,槽底圆直径,磁环轴向截面积,实际质量密度,标称质量密度,片数,初级绕组匝数,次级绕组匝数,磁路截面积,叠压系数,表观磁路长度,备注
      itemHeader1: [1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1], //定子冲片,
      itemHeader2: [1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1], //一维单片
      itemHeader3: [1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1], //叠心圆环
      itemHeader4: [1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1], //实心圆环
      itemHeader5: [1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1], //卷绕铁心
      itemHeader6: [1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], //爱泼斯坦方圈
      itemHeader7: [1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1], //闭路铁心
      itemHeader8: [1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1], //开路铁心
      itemHeader9: [1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1], //微小异形
      typeId: '定子冲片',
      //类型选择
      menulist: [
        {
          id: '定子冲片',
          authName: '定子冲片'
        },
        {
          id: '一维单片',
          authName: '一维单片'
        },
        {
          id: '叠片圆环',
          authName: '叠片圆环'
        },
        {
          id: '实心圆环',
          authName: '实心圆环'
        },
        {
          id: '卷绕铁心',
          authName: '卷绕铁心'
        },
        {
          id: '爱泼斯坦方圈',
          authName: '爱泼斯坦方圈'
        },
        {
          id: '闭路铁心',
          authName: '闭路铁心'
        },
        {
          id: '开路铁心',
          authName: '开路铁心'
        },
        {
          id: '微小异形',
          authName: '微小异形'
        }
      ],
      parameterList: [],
      addParameterVisible: false,
      total: 0,
      queryInfo: {
        // number: '',
        // mark: '',
        // supplier: '',
        pageNum: 1,
        pageSize: 10
      }
    }
  },
  created() {
    this.loadData()
  },
  methods: {
    handleChange(info) {
      if (info.file.status === 'done') {
        if (info.file.response.code == '201') {
          this.$message.success('重新上传文件成功！')
        } else if (info.file.response.code == '200') {
          this.$message.success('上传文件成功！')
        }
      }
    },
    //模板导出按钮
    exportData() {
      this.axios({
        baseURL: 'http://59.172.104.174:30669',
        url: `/admin/downLoadLessonFile?name=牌号标签`,
        methods: 'GET',
        responseType: 'blob'
      }).then(res => {
        const blob = new Blob([res.data])
        const url = window.URL.createObjectURL(blob)
        const link = document.createElement('a')
        link.style.display = 'none'
        link.download = `牌号标签.xlsx`
        link.href = url
        link.click()
      })
    },
    queryData() {},
    loadData() {
      if (this.typeId === '定子冲片') {
        this.tableHeader = this.itemHeader1
      } else if (this.typeId === '一维单片') {
        this.tableHeader = this.itemHeader2
      } else if (this.typeId === '叠片圆环') {
        this.tableHeader = this.itemHeader3
      } else if (this.typeId === '实心圆环') {
        this.tableHeader = this.itemHeader4
      } else if (this.typeId === '卷绕铁心') {
        this.tableHeader = this.itemHeader5
      } else if (this.typeId === '爱泼斯坦方圈') {
        this.tableHeader = this.itemHeader6
      } else if (this.typeId === '闭路铁心') {
        this.tableHeader = this.itemHeader7
      } else if (this.typeId === '开路铁心') {
        this.tableHeader = this.itemHeader8
      } else if (this.typeId === '微小异形') {
        this.tableHeader = this.itemHeader9
      }
    },
    //导入
    showImport() {
      this.importTag = true
    },
    //分页控制
    handleSizeChange(newSize) {
      this.queryInfo.pageSize = newSize
    },
    handleCurrentChange(newPage) {
      this.queryInfo.pageNum = newPage
    }
  }
}
</script>

<style scoped></style>
